Avoid a crash in testcalendar
authorMatthias Clasen <mclasen@redhat.com>
Wed, 24 Dec 2014 02:47:50 +0000 (21:47 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 24 Dec 2014 02:47:50 +0000 (21:47 -0500)
When changing between months, we can get into a situation like
'February 30", which GDate doesn't accept. Don't crash in that
case.

tests/testcalendar.c

index 497901113d0faa1d4ab3792cea7bb1fdb75f52ef..16f04bf5d10bcb1b82247770603c1833047e1fa1 100644 (file)
@@ -67,10 +67,16 @@ calendar_date_to_string (CalendarData *data,
 
   gtk_calendar_get_date (GTK_CALENDAR(data->window),
                         &year, &month, &day);
-  date = g_date_new_dmy (day, month + 1, year);
-  g_date_strftime (buffer, buff_len-1, "%x", date);
-
-  g_date_free (date);
+  if (g_date_valid_dmy (day, month + 1, year))
+    {
+      date = g_date_new_dmy (day, month + 1, year);
+      g_date_strftime (buffer, buff_len-1, "%x", date);
+      g_date_free (date);
+    }
+  else
+    {
+      g_snprintf (buffer, buff_len - 1, "%d/%d/%d (invalid)", month + 1, day, year);
+    }
 }
 
 static void